home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / HENSA / MISC / SHELL.ARC / Shell / Sources / c / Label < prev    next >
Text File  |  1994-07-27  |  3KB  |  153 lines

  1. #include <string.h>
  2. #include <stdarg.h>
  3. #include <stdio.h>
  4.  
  5. #include "DeskLib:WimpSWIs.h"
  6.  
  7. #include "Shell.Shell.h"
  8. #include "Shell.Extra.h"
  9. #include "Shell.Check.h"
  10. #include "Shell.SafeAlloc.h"
  11. #include "Shell.Label.h"
  12.  
  13.  
  14. static void    Shell_LabelDisplayer(
  15.     Shell_convertpoint    convert,
  16.     wimp_point        rectsize,
  17.     void            *reference,
  18.     const wimp_rect        *redrawrect
  19.     )
  20. {
  21.     char *text = (char *) reference;
  22. UNUSED( redrawrect);
  23.  
  24. Shell_PrintString( text, 0, rectsize.y, convert);
  25. return;
  26. }
  27.  
  28.  
  29.  
  30. static BOOL Shell_LabelSaver( char *filename, Shell_rectblock *r)
  31. {    FILE    *f;
  32.     char *text = (char *) r->reference;
  33.  
  34. f = fopen( filename, "w");
  35. if (!f)    return FALSE;
  36.  
  37. fprintf( f, text);
  38. fclose( f);
  39. return TRUE;
  40. }
  41.  
  42.  
  43.  
  44. Shell_rectblock    *Shell_Label(
  45.     Shell_windblock *w,
  46.     int x, int y,
  47.     int forecol, int backcol,
  48.     const char *text
  49.     )
  50. {
  51.     wimp_rect    rect;
  52.     int        len        = strlen( text);
  53.     char        *text2;
  54.     Shell_rectblock    *r;
  55.  
  56. rect.min.x = x; rect.max.x = x + Shell_TEXTXSIZE*len;
  57. rect.max.y = y; rect.min.y = y - Shell_TEXTYSIZE;
  58.  
  59. text2 = Shell_SafeMalloc( 1+len);
  60. strcpy( text2, text);
  61.  
  62. r = Shell_AddRectangle( w, &rect, Shell_LabelDisplayer, (void *) text2);
  63. Shell_MakeRectIcon( r, forecol, backcol, "R1");
  64. r->saver = Shell_LabelSaver;
  65. return r;
  66.  
  67. }
  68.  
  69.  
  70.  
  71.  
  72. Shell_rectblock    *Shell_Labelf(
  73.     Shell_windblock *w,
  74.     int x, int y,
  75.     int forecol, int backcol,
  76.     const char *fmt, ...
  77.     )
  78. {
  79.     va_list args;
  80.  
  81. va_start( args, fmt);
  82. vsprintf( Shell_string, fmt, args);
  83. va_end( args);
  84. return Shell_Label( w, x, y, forecol, backcol, Shell_string);
  85. }
  86.  
  87.  
  88.  
  89. /*
  90. #define MAX( a, b)    (( (a) > (b) ) ? a : b )
  91. */
  92.  
  93. void    Shell_ReLabel( Shell_rectblock *r, const char *text)
  94. {
  95.     wimp_rect    oldiconrect;
  96.     int        newlen = strlen( text);
  97.     int        oldsize = r->rect.max.x - r->rect.min.x;
  98.     int        newsize;
  99.  
  100. oldiconrect = r->icon.workarearect;
  101.  
  102. r->reference = Shell_SafeRealloc( r->reference, 1 + newlen);
  103. strcpy( (char *) r->reference, text);
  104.  
  105. r->rect.max.x = r->rect.min.x + Shell_TEXTXSIZE * newlen;
  106.  
  107. newsize = r->rect.max.x - r->rect.min.x;
  108.  
  109. if ( newsize != oldsize)    {
  110.     /* Redraw whole icon if it has changed size.    */
  111.  
  112.     Shell_ResizeIconRect( r);
  113.     /* Recalculate the icon border. Also forces redraw if rect is visible    */
  114.  
  115.     if ( oldsize > newsize)    {
  116.         /* Need to erase extra space from the old (larger) icon.    */
  117.         window_redrawblock block;
  118.         block.window        = r->window;
  119.         block.rect        = oldiconrect;
  120.         block.rect.min.x    = r->icon.workarearect.max.x;
  121.         Wimp_ForceRedraw( &block);
  122.         }
  123.     }
  124.  
  125. else    Shell_ForceRectRedraw( r);    /* Don't have to do this if the rect has changed size    */
  126. }
  127.  
  128.  
  129.  
  130.  
  131. void Shell_ReLabelf( Shell_rectblock *r, const char *fmt, ...)
  132. {    va_list args;
  133. va_start( args, fmt);
  134. vsprintf( Shell_string, fmt, args);
  135. va_end( args);
  136. Shell_ReLabel( r, Shell_string);
  137. }
  138.  
  139.  
  140.  
  141.  
  142. void Shell_ReLabelfSlow( Shell_rectblock *r, const char *fmt, ...)
  143. {    va_list args;
  144.     clock_t t = clock();
  145. if ( t - r->last_update >= r->update_time)    {
  146.     r->last_update = t;
  147.     va_start( args, fmt);
  148.     vsprintf( Shell_string, fmt, args);
  149.     va_end( args);
  150.     Shell_ReLabel( r, Shell_string);
  151.     }
  152. }
  153.